import config from "@/config"
import http from "@/utils/request"


// 生产
export default {
  // 生产单管理
  getProduceOrderList: {
    url: `${config.API_URL}/produce/list`,
    name: "获取生产单列表",
    get: function (param) {
      return new Promise((resolve, reject) => {
        http.get(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  addProduceOrder: {
    url: `${config.API_URL}/produce/add`,
    name: "添加生产单",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  updateProduceOrder: {
    url: `${config.API_URL}/produce/update`,
    name: "修改生产单",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  deleteProduceOrder: {
    url: `${config.API_URL}/produce/delete`,
    name: "删除生产单",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getProduceOrderById: {
    url: `${config.API_URL}/produce/listById`,
    name: "根据id获取生产单详情",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  submitCheck: {
    url: `${config.API_URL}/produce/commitAudit`,
    name: "提交生产单审核",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  checkProduceOrder: {
    url: `${config.API_URL}/produce/audit`,
    name: "审核生产单",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
  updateProduceStatus: {
    url: `${config.API_URL}/produce/changeProduceType`,
    name: "更改生产状态",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
  getProduceListByIds: {
    url: `${config.API_URL}/produceScheduling/getProduceProduce`,
    name: "获取多个生产单详情",
    get: function (data) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  addProduction: {
    url: `${config.API_URL}/produceScheduling/add`,
    name: "添加排产",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  exportProduceProducts: {
    url: `${config.API_URL}/produceProducts/export`,
    name: "导出生产单",
    get: function (data) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data, {
          responseType: 'blob',
        }).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  products: {
    getProductsList: {
      url: `${config.API_URL}/produceProducts/list`,
      name: "获取生产单产品列表",
      get: function (param) {
        return new Promise((resolve, reject) => {
          http.get(this.url, param).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },

    updateProductsStatus: {
      url: `${config.API_URL}/produceProducts/updateStatus`,
      name: "更改产品状态",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.postParam(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    enterProductNum: {
      url: `${config.API_URL}/produceProducts/enter`,
      name: "根据生产单id获取产品列表",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getProductionList: {
      url: `${config.API_URL}/produceScheduling/getScheduling`,
      name: "获取生产单排产信息列表",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
  },

  // 送货管理
  deliver: {
    getDeliverList: {
      url: `${config.API_URL}/deliver/list`,
      name: "获取送货列表",
      get: function (param) {
        return new Promise((resolve, reject) => {
          http.get(this.url, param).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },

    addDeliver: {
      url: `${config.API_URL}/deliver/add`,
      name: "添加送货",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },

    updateDeliver: {
      url: `${config.API_URL}/deliver/update`,
      name: "修改送货",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },

    deleteDeliver: {
      url: `${config.API_URL}/deliver/delete`,
      name: "删除送货",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.postParam(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },

    getDeliverDetailById: {
      url: `${config.API_URL}/deliver/listByDeliverId`,
      name: "根据id获取送货详情",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.postParam(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },

    submitCheck: {
      url: `${config.API_URL}/deliver/commitAudit`,
      name: "提交送货审核",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.postParam(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },

    checkDeliver: {
      url: `${config.API_URL}/deliver/audit`,
      name: "审核送货",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.postParam(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    updateStatus: {
      url: `${config.API_URL}/deliver/updateStatus`,
      name: "更改送货状态",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getAddress: {
      url: `${config.API_URL}/deliver/address`,
      name: "获取客户地址",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    selectProductsByDeliverId: {
      url: `${config.API_URL}/deliver/listById`,
      name: "根据送货id获取产品列表",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getDeliverAddress: {
      url: `${config.API_URL}/produce/getAddress`,
      name: "获取送货地址",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },

    getProduceCountData: {
      url: `${config.API_URL}/produce/statistics`,
      name: "获取生产统计",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },

    getContractOtherFile: {
      url: `${config.API_URL}/produce/getContractOtherFile`,
      name: "获取合同附件",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },

    exportDeliver: {
      url: `${config.API_URL}/deliver/export`,
      name: "导出送货清单",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data, { responseType: 'blob', }).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
  },

  produceProducts: {
    selectProductsByProduceId: {
      url: `${config.API_URL}/produceProducts/list`,
      name: "根据生产单id获取产品列表",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    selectProductsByDeliverId: {
      url: `${config.API_URL}/produceProducts/productsList`,
      name: "根据送货单id获取产品列表",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
  },

  // 设备
  equipment: {
    getEquipmentList: {
      url: `${config.API_URL}/equipment/list`,
      name: "获取设备列表",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },

    addEquipment: {
      url: `${config.API_URL}/equipment/add`,
      name: "添加设备",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    updateEquipment: {
      url: `${config.API_URL}/equipment/update`,
      name: "修改设备",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    handleEnterData: {
      url: `${config.API_URL}/equipment/enter`,
      name: "录入数据",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },

  },

  // 外发管理
  productionOut: {
    getProductionOutlist: {
      url: `${config.API_URL}/schedulingOut/list`,
      name: "获取外发列表",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    addProductionOut: {
      url: `${config.API_URL}/schedulingOut/add`,
      name: "添加外发",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    handleEnterData: {
      url: `${config.API_URL}/schedulingOut/enter`,
      name: "确认数据",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getProductionOutById: {
      url: `${config.API_URL}/schedulingOut/detail`,
      name: "获取外发详情",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getProductionOutInfo: {
      url: `${config.API_URL}/schedulingOut/getSchedulingOut`,
      name: "获取外发产品信息列表",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
  },

  // 退货管理
  returnProduct: {
    getReturnProductList: {
      url: `${config.API_URL}/rejected/list`,
      name: "获取退货列表",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    addReturnProduct: {
      url: `${config.API_URL}/rejected/add`,
      name: "添加退货",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    updateReturnProduct: {
      url: `${config.API_URL}/rejected/update`,
      name: "修改退货",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    cancelReturnProduct: {
      url: `${config.API_URL}/rejected/cancel`,
      name: "取消退货",
      delete: function (data) {
        return new Promise((resolve, reject) => {
          http.delete(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getReturnProductById: {
      url: `${config.API_URL}/rejected/detail`,
      name: "退货详情",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getReturnProduct: {
      url: `${config.API_URL}/rejected/getRejectedProductList`,
      name: "退货产品详情--可发货产品",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getIsDeliverList: {
      url: `${config.API_URL}/rejected/getIsDeliverList`,
      name: "获取有发货的生产单",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    addRepair: {
      url: `${config.API_URL}/repair/add`,
      name: "添加维修",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    addDeliver: {
      url: `${config.API_URL}/deliver/addRejected`,
      name: "添加发货",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
  },

  //维修管理
  repair: {
    getRepairList: {
      url: `${config.API_URL}/repair/list`,
      name: "获取维修列表",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getRepairById: {
      url: `${config.API_URL}/repair/detail`,
      name: "获取维修详情",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    deleteRepair: {
      url: `${config.API_URL}/repair/delete`,
      name: "删除维修",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.postParam(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    confirmRepair: {
      url: `${config.API_URL}/repair/updateStatus`,
      name: "确认维修",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.postParam(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
  },

  /**
   * 退款管理
   */

  refund: {
    getRefundPageList: {
      url: `${config.API_URL}/refund/pageList`,
      name: "退款分页列表",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    addRefund: {
      url: `${config.API_URL}/refund/add`,
      name: "添加退款",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    updateRefund: {
      url: `${config.API_URL}/refund/update`,
      name: "修改退款",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.post(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getRefundDetail: {
      url: `${config.API_URL}/refund/detail`,
      name: "获取退款详情",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    updateStatus: {
      url: `${config.API_URL}/refund/updateStatus`,
      name: "修改退款状态",
      post: function (data) {
        return new Promise((resolve, reject) => {
          http.postParam(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
  },

  // 工单统计

  workOrder: {
    getRunningTime: {
      url: `${config.API_URL}/tickets/duration`,
      name: "获取设备运行时长",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getWorkOrderList: {
      url: `${config.API_URL}/tickets/list`,
      name: "获取实时工单列表",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getDeliverCount: {
      url: `${config.API_URL}/tickets/deliverStatistics`,
      name: "获取送货统计",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    },
    getWorkOrderCount: {
      url: `${config.API_URL}//tickets/ticketStatistics`,
      name: "获取工单统计",
      get: function (data) {
        return new Promise((resolve, reject) => {
          http.get(this.url, data).then((response) => {
            resolve(response)
          }).catch((error) => {
            resolve(error.data)
          })
        })
      }
    }
  }
}
